package stat;

import java.util.HashMap;
import java.util.Map;

import parser.XYZParserConstants;
import parser.Token;

public class TokenAnalysis {
	
	private int [] keywordCount;
	private Map<String,Integer> map;
	
	public TokenAnalysis(){
		this.map = new HashMap<String, Integer>();
		this.keywordCount = new int[23];
		for(int i = 0; i < 23; i++)
			keywordCount[i] = 0;
	}
	
	public void countToken(Token tk){
		if(tk.kind >= 10 && tk.kind <= 32)
			++ keywordCount[tk.kind-10];
		else if(tk.kind == XYZParserConstants.IDENTIFIER){
			if(map.containsKey(tk.image)){
				int oldValue = map.get(tk.image);
				map.put(tk.image, oldValue+1);
			}
			else
				map.put(tk.image, 1);	
		}
	}
	
	public int [] getKeyWordCount(){
		return keywordCount;
	}
	
	public Map<String,Integer> getMap(){
		return map;
	}

}
